//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "HazardRateStructure.h"
using namespace Cephei::QL::Termstructures::Credit;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/DefaultProbabilityTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (boost::shared_ptr<QuantLib::HazardRateStructure>& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
#ifdef HANDLE
	_phHazardRateStructure = NULL;
#endif
	_ppHazardRateStructure = &childNative;
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
}
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (QuantLib::HazardRateStructure& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
#ifdef HANDLE
	_phHazardRateStructure = NULL;
#endif
	_ppHazardRateStructure = new boost::shared_ptr<QuantLib::HazardRateStructure> (&childNative);
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
    _HazardRateStructureOwner = owner;
    _DefaultProbabilityTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (CHazardRateStructure^ copy) : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
#ifdef HANDLE
	_phHazardRateStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppHazardRateStructure = new boost::shared_ptr<QuantLib::HazardRateStructure> (copy->GetShared());
        _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
    }
}
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (PLATFORM::Type^ t) : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
#ifdef HANDLE
	_phHazardRateStructure = NULL;
#endif
	if (!t->IsSubclassOf(CHazardRateStructure::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (QuantLib::Handle<QuantLib::HazardRateStructure>& childNative, Object^ owner)  : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
	_phHazardRateStructure = &childNative;
	_ppHazardRateStructure = &static_cast<boost::shared_ptr<QuantLib::HazardRateStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
    _HazardRateStructureOwner = owner;
}
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (QuantLib::Handle<QuantLib::HazardRateStructure> childNative)  : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
	_phHazardRateStructure = &childNative;
	_ppHazardRateStructure = &static_cast<boost::shared_ptr<QuantLib::HazardRateStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Credit::CHazardRateStructure::CHazardRateStructure (QuantLib::HazardRateStructure childNative)  : CDefaultProbabilityTermStructure(CHazardRateStructure::typeid)
{
#ifdef HANDLE
	_phHazardRateStructure = NULL;
#endif
	_ppHazardRateStructure = new boost::shared_ptr<QuantLib::HazardRateStructure> (new QuantLib::HazardRateStructure (childNative));
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppHazardRateStructure));
}
#endif

Cephei::QL::Termstructures::Credit::CHazardRateStructure::~CHazardRateStructure ()
{
    if (_ppHazardRateStructure != NULL)
    {
	    delete _ppHazardRateStructure;
        _ppHazardRateStructure = NULL;
    }
}
Cephei::QL::Termstructures::Credit::CHazardRateStructure::!CHazardRateStructure ()
{
    if (_ppHazardRateStructure != NULL)
    {
	    delete _ppHazardRateStructure;
    }
}
QuantLib::HazardRateStructure& Cephei::QL::Termstructures::Credit::CHazardRateStructure::GetReference ()
{
    if (_ppHazardRateStructure == NULL) throw REFNEW NativeNullException ();
	return **_ppHazardRateStructure;
}
boost::shared_ptr<QuantLib::HazardRateStructure>& Cephei::QL::Termstructures::Credit::CHazardRateStructure::GetShared ()
{
    if (_ppHazardRateStructure == NULL) throw REFNEW NativeNullException ();
	return *_ppHazardRateStructure;
}
QuantLib::HazardRateStructure* Cephei::QL::Termstructures::Credit::CHazardRateStructure::GetPointer ()
{
    if (_ppHazardRateStructure == NULL) throw REFNEW NativeNullException ();
	return &**_ppHazardRateStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::HazardRateStructure>& Cephei::QL::Termstructures::Credit::CHazardRateStructure::GetHandle ()
{
	if (_phHazardRateStructure == NULL)
	{
		_phHazardRateStructure = new Handle<QuantLib::HazardRateStructure> (*_ppHazardRateStructure);
	}
	return *_phHazardRateStructure;
}
#endif
bool Cephei::QL::Termstructures::Credit::CHazardRateStructure::HasNative () 
{
	return (_ppHazardRateStructure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

